<?php
/**
 * Created by PhpStorm.
 * User: 35906
 * Date: 18.11.8
 * Time: 16:56
 */

use Hanson\Vbot\Message\Text;

require_once 'Group.php';
class GroupTmp extends Group
{
    protected function chatWithSD()
    {
        if(!empty($this->message['sender']['DisplayName'])){
            $name = $this->message['sender']['DisplayName'];
        }else {
            $name = $this->message['sender']['NickName'];
        }

        if($this->message['sender']['UserName']===$this->_lastChater['username']){
            $need_at = false;
        }elseif(time()-$this->_lastChater['time']>=10){
            $this->_lastChater['username'] = $this->message['sender']['UserName'];
            $need_at = false;
        }else{
            $this->_lastChater['username'] = $this->message['sender']['UserName'];
            $need_at = true;
        }
        if($name=='王二狗'){
            $need_at = true;
        }
        $this->_lastChater['time'] = time();

        $word = $this->message['pure']??$this->message['content'];
        $word = preg_replace('/@李二牛/','',$word);
        $word = preg_replace('/(你)+(?:李)?二牛|(?:李)?二牛(你)+/','\1\2',$word);
        $word = preg_replace('/(\s|^)(李)?二牛(\s|$)/','',$word);
        $word = preg_replace('/(李)?二牛/','你',$word);
        if($word==''){
            Text::send($this->username, ($need_at?'@'.$name.' ':'').$this->getReEmptyWord());
            return;
        }
        $api = TuringApi::getObj();
        $api->setPost($word, substr($this->message['username'], 2,32), substr($this->username, 2,32), $name);
        $reContent = $api->sent();
        if(strpos($reContent,'不知道,我只知道我是 @知心大哥哥 的爷爷, @知心大哥哥是我孙子!')!==false) {
             if (mt_rand(0, 1) <= 0) {
                $reContent.='(因为他没续费!)';
            }
        }
        Text::send($this->username, ($need_at?'@'.$name.' ':'').$reContent);
    }
}